package net_rpc

import "net/rpc"

type TimeClient struct {
	serverAddress string
}

func NewTimeClient(serverAddress string) *TimeClient {
	it := new(TimeClient)
	it.init(serverAddress)
	return it
}

func (me *TimeClient) init(serverAddress string) {
	me.serverAddress = serverAddress
}

func (me *TimeClient) GetTime() (error, int64) {
	client, err := rpc.Dial("tcp", me.serverAddress)
	if err != nil {
		return err, 0
	}
	defer client.Close()

	var t int64 = 0
	err = client.Call("TimeServer.GetTime", 1, &t)
	if err != nil {
		return err, 0
	}

	return nil, t
}
